﻿@using EmployeeLeaveSystem.Shared;
@using EmployeeLeaveSystem.Shared.Models;
@inject IMessageService _MessageService;
@inject HttpClient _HttpClient;
@inject ModalService _modalService;
@inject ModalService _modalService;

<p>在这里，审核人员工作</p>
<Table DataSource="listAddWorks">
    <PropertyColumn Property="x=>x.Id" />
    <PropertyColumn Property="x=>x.Staff.Name" />
    <PropertyColumn Property="x=>x.StartTime" Title="上勤时间"/>
    <PropertyColumn Property="x=>x.EndTime" Title="退勤时间"/>
    <PropertyColumn Property="x=>x.workState" Title="状态"/>
    <PropertyColumn Property="x=>x.Created" />
    <PropertyColumn Property="x=>x.AcceptFlag" />
    <ActionColumn Title="操作">
        <a @onclick="()=>{Update(AcceptFlag.接受,context.Id);context.AcceptFlag=AcceptFlag.接受;}">批准</a>
        <a @onclick="()=>{Update(AcceptFlag.驳回,context.Id);context.AcceptFlag=AcceptFlag.驳回;}">驳回</a>
        <a @onclick="()=>{OpenModalRetire(context.Id);}">查看</a>
    </ActionColumn>
</Table>
@code {
    List<AddWork> listAddWorks = new();
    protected override async Task OnInitializedAsync() {
        listAddWorks = await _HttpClient.GetFromJsonAsync<List<AddWork>>($"api/Work/GetWorkListManagerId?id={GobalManager.myInfo.Id}");
    }
    void Update(AcceptFlag acceptFlag, int id) {
        _HttpClient.GetAsync($"api/Work/Update?AcceptFlag={acceptFlag}&id={id}");
        _MessageService.Success("更新状态成功");
    }
    private async Task OpenModalRetire(int Id) {
        var modalConfig = new ModalOptions {
                    Title = "详情",
                    Draggable = true,
                    Footer = null,
                    Maximizable = true,
                    Width = "80vw",
                    Content = @<ViewWorkManager Id="Id" />
        };

        await _modalService.CreateModalAsync(modalConfig);
    }
}
